4
תגובות
מערכת מזג אוויר
פתח
אנונימי
,
תראו אני בנייתי מערכת מזג אוויר שעובדת עם הAPI של GOOGLE.
בWAMPSERVER היא עובדת מצויין אך בשרת היא עושה בעיות
הבעיות התחילו אחרי שהוספתי את האפשרות לבחור עיר
האתר: http://yourpage.co.il/ כמו שאתם יכולים לראות זה מראה -17 שמשנים עיר אבל בWAMPSERVER זה מראה פרטים כמו שצריך...
הקוד של הWEATHER
הקוד של HELPER: (יש שם עוד דברים שלא קשורים למזג אוויר)
בWAMPSERVER היא עובדת מצויין אך בשרת היא עושה בעיות
הבעיות התחילו אחרי שהוספתי את האפשרות לבחור עיר
האתר: http://yourpage.co.il/ כמו שאתם יכולים לראות זה מראה -17 שמשנים עיר אבל בWAMPSERVER זה מראה פרטים כמו שצריך...
הקוד של הWEATHER
<?php
class Weather
{
const url = "http://www.google.com/ig/api?weather=israel,";
public static function getStatHe($val)
{
$end = array("Chance of Rain","Mostly Sunny","Clear","Partly Sunny");
$hew = array("סיכוי לגשם","בעיקר שמש","בהיר","מעונן חלקית");
return str_replace($end, $hew, $val);
}
public static function F2C($f)
{
return intval( ($f - 32) * (5/9) );
}
public static function showWeatherStat($day,$city='tel-aviv')
{
$xml_weather = file_get_contents(self::url . $city, 0);
$xml_weather = new SimplexmlElement($xml_weather);
foreach($xml_weather->weather->forecast_conditions as $check)
{
if($check->day_of_week['data']== $day)
$today = $check;
}
$icon = $today->icon['data'];
$temp = (self::F2C($today->low['data']) + self::F2C($today->high['data'])) / 2;
echo "
<img src='http://www.google.com/$icon' />
<table>
<tr>
<td><strong>מצב</strong></td>
<td>".self::getStatHe($today->condition['data'])."</td>
</tr>
<tr>
<td><strong>מעלות</strong></td>
<td>$temp <span style='font-size:16px'>°</span></td>
</tr>
</table>
";
}
public static function showWeather()
{
$xml_weather = file_get_contents(self::url . 'tel-aviv', 0);
$xml_weather = new SimplexmlElement($xml_weather);
echo CHtml::openTag("select", array("onchange"=>"changeWeatherDay()","id"=>"weather_day","style"=>"width:100px"));
foreach($xml_weather->weather->forecast_conditions as $weather)
{
echo CHtml::openTag("option",array("value"=>$weather->day_of_week['data']));
echo Helper::convertDay($weather->day_of_week['data']);
echo CHtml::closeTag("option");
}
echo CHtml::closeTag("select") . "<br />";
echo CHtml::openTag("select", array("onchange"=>"changeWeatherDay()","id"=>"weather_city","style"=>"width:100px"));
foreach(Helper::getCities() as $city)
{
echo CHtml::openTag("option",array("value"=>$city));
echo Helper::city2hew($city);
echo CHtml::closeTag("option");
}
echo CHtml::closeTag("select");
echo CHtml::openTag("div",array("id"=>"weather"));
self::showWeatherStat( date("D") );
echo CHtml::closeTag("div");
}
}
?>
class Weather
{
const url = "http://www.google.com/ig/api?weather=israel,";
public static function getStatHe($val)
{
$end = array("Chance of Rain","Mostly Sunny","Clear","Partly Sunny");
$hew = array("סיכוי לגשם","בעיקר שמש","בהיר","מעונן חלקית");
return str_replace($end, $hew, $val);
}
public static function F2C($f)
{
return intval( ($f - 32) * (5/9) );
}
public static function showWeatherStat($day,$city='tel-aviv')
{
$xml_weather = file_get_contents(self::url . $city, 0);
$xml_weather = new SimplexmlElement($xml_weather);
foreach($xml_weather->weather->forecast_conditions as $check)
{
if($check->day_of_week['data']== $day)
$today = $check;
}
$icon = $today->icon['data'];
$temp = (self::F2C($today->low['data']) + self::F2C($today->high['data'])) / 2;
echo "
<img src='http://www.google.com/$icon' />
<table>
<tr>
<td><strong>מצב</strong></td>
<td>".self::getStatHe($today->condition['data'])."</td>
</tr>
<tr>
<td><strong>מעלות</strong></td>
<td>$temp <span style='font-size:16px'>°</span></td>
</tr>
</table>
";
}
public static function showWeather()
{
$xml_weather = file_get_contents(self::url . 'tel-aviv', 0);
$xml_weather = new SimplexmlElement($xml_weather);
echo CHtml::openTag("select", array("onchange"=>"changeWeatherDay()","id"=>"weather_day","style"=>"width:100px"));
foreach($xml_weather->weather->forecast_conditions as $weather)
{
echo CHtml::openTag("option",array("value"=>$weather->day_of_week['data']));
echo Helper::convertDay($weather->day_of_week['data']);
echo CHtml::closeTag("option");
}
echo CHtml::closeTag("select") . "<br />";
echo CHtml::openTag("select", array("onchange"=>"changeWeatherDay()","id"=>"weather_city","style"=>"width:100px"));
foreach(Helper::getCities() as $city)
{
echo CHtml::openTag("option",array("value"=>$city));
echo Helper::city2hew($city);
echo CHtml::closeTag("option");
}
echo CHtml::closeTag("select");
echo CHtml::openTag("div",array("id"=>"weather"));
self::showWeatherStat( date("D") );
echo CHtml::closeTag("div");
}
}
?>
הקוד של HELPER: (יש שם עוד דברים שלא קשורים למזג אוויר)
<?php
class Helper
{
public static function convertDay($day,$to='he')
{
$eng = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
$hew = array("ראשון","שני","שלישי","רביעי","חמישי","שישי","שבת");
if($to == 'he')
return str_replace($eng, $hew, $day);
return str_replace($hew, $eng, $day);
}
public static function getIP()
{
if( getenv("HTTP_CLIENT_IP") ) return getenv("HTTP_CLIENT_IP");
if( getenv("HTTP_X_FORWARDED_FOR") ) return getenv("HTTP_X_FORWARDED_FOR");
if( getenv("REMOTE_ADDR") ) return getenv("REMOTE_ADDR");
if(isset($_SERVER['REMOTE_ADDR'])) return $_SERVER['REMOTE_ADDR'];
return null;
}
public static function getFileType($name)
{
return strtolower(end(explode(".",$name)));
}
public static function city2hew($city)
{
$eng = self::getCities();
$hew = array("תל אביב","חדרה","אילת","ירושלים","חיפה",'כפר סבא','באר שבע','קרית שמונה','נצרת','אריאל','מצפה רמון');
return str_replace($eng, $hew, $city);
}
public static function getCities()
{
return array("tel-aviv","hadera",'eilat','jerusalem','haifa',"kfar-saba","beer-sheva",'kiryat-shmona','nazareth','ariel','mitzpe-ramon');
}
}
?>
class Helper
{
public static function convertDay($day,$to='he')
{
$eng = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
$hew = array("ראשון","שני","שלישי","רביעי","חמישי","שישי","שבת");
if($to == 'he')
return str_replace($eng, $hew, $day);
return str_replace($hew, $eng, $day);
}
public static function getIP()
{
if( getenv("HTTP_CLIENT_IP") ) return getenv("HTTP_CLIENT_IP");
if( getenv("HTTP_X_FORWARDED_FOR") ) return getenv("HTTP_X_FORWARDED_FOR");
if( getenv("REMOTE_ADDR") ) return getenv("REMOTE_ADDR");
if(isset($_SERVER['REMOTE_ADDR'])) return $_SERVER['REMOTE_ADDR'];
return null;
}
public static function getFileType($name)
{
return strtolower(end(explode(".",$name)));
}
public static function city2hew($city)
{
$eng = self::getCities();
$hew = array("תל אביב","חדרה","אילת","ירושלים","חיפה",'כפר סבא','באר שבע','קרית שמונה','נצרת','אריאל','מצפה רמון');
return str_replace($eng, $hew, $city);
}
public static function getCities()
{
return array("tel-aviv","hadera",'eilat','jerusalem','haifa',"kfar-saba","beer-sheva",'kiryat-shmona','nazareth','ariel','mitzpe-ramon');
}
}
?>